<?php

// 直接调用 Hyperf JSON-RPC 服务

echo "=== 测试直接 RPC 调用 ===\n\n";

// 测试 1: DataService@getCampuses
echo "1. 测试 DataService@getCampuses\n";
$url = 'http://localhost:9509/data/getCampuses';
$data = [
    'jsonrpc' => '2.0',
    'method' => 'data/getCampuses',
    'params' => [['requestId' => 'test-' . uniqid()]],
    'id' => 1,
];

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
]);

$response = curl_exec($ch);
curl_close($ch);

echo "Response: $response\n";
$responseData = json_decode($response, true);
if (isset($responseData['result'])) {
    echo "✅ 成功！结果: " . json_encode($responseData['result'], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n";
} else {
    echo "❌ 失败: " . ($responseData['error']['message'] ?? 'Unknown error') . "\n\n";
}

// 测试 2: NoticeService@getNotice2Data
echo "2. 测试 NoticeService@getNotice2Data\n";
$url = 'http://localhost:9502/notice/getNotice2Data';
$data = [
    'jsonrpc' => '2.0',
    'method' => 'notice/getNotice2Data',
    'params' => [],
    'id' => 2,
];

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Content-Type: application/json',
]);

$response = curl_exec($ch);
curl_close($ch);

echo "Response: $response\n";
$responseData = json_decode($response, true);
if (isset($responseData['result'])) {
    echo "✅ 成功！结果: " . json_encode($responseData['result'], JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n";
} else {
    echo "❌ 失败: " . ($responseData['error']['message'] ?? 'Unknown error') . "\n\n";
}

echo "=== 测试完成 ===\n";

